#include <iostream>
#include <string>
#include <vector>
using namespace std;

int strToInt(const std::string s, int k){
	int sign=1;
	int length=s.length();
	int count=0;
	if (s[0]=='+'){
		count++;
		sign=1;
	}else if(s[0]=='-'){
		count++;
		sign=-1;
	}
	int num=0;
	for (int i=count; i<length; i++){
		if (s[i]>='0' && s[i]<='9'){
            num=num*k+s[i]-'0';
        }else{
            break;
        }
	}
	return num*sign;
}
int main() 
{ 
	//TODO
	string s;
	int k;
	cin>>s>>k;
	cout<<strToInt(s,k)<<endl; 
	return 0; 
}
